package ui;

import java.awt.BorderLayout;
import java.awt.GridLayout;

import javax.swing.*;
import javax.swing.border.EmptyBorder;

import core.MenuItemType;

import java.rmi.RemoteException;

//comment so we can code review - remove later
public class ViewMenuScreen extends BaseScreen {
	
	private JFrame frame;
	
	public ViewMenuScreen()
	{				
		frame = new JFrame();
		frame.setTitle("View Menu");
		frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		frame.setSize(650, 550);
		frame.setLayout(new BorderLayout());
		
		try {
			doMenu();
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		frame.setVisible(true);
	}
	
	private void doMenu() throws RemoteException
	{
		JPanel mainContent_panel = new JPanel();
		//added 2 for the daily special (1 for the label, 1 for the item info
		int itemSlots = store.getNumberMenuItems() + store.getMenuItemTypeValues().length + 2;
		mainContent_panel.setLayout(new GridLayout(itemSlots, 1));
		
		/* Making the daily special panels */
		JLabel special_lbl = new JLabel("<HTML><FONT SIZE = \"5\">Daily Special</FONT></HTML>");
		JLabel specialName_lbl = new JLabel(store.getDailySpecialName());
		JLabel specialPrice_lbl = new JLabel(store.getDailySpecialPrice());
		JLabel specialDesc_lbl = new JLabel(store.getDailySpecialDescription());
		
		mainContent_panel.add(new JPanel().add(special_lbl));
		
		JPanel special_panel = new JPanel();
		JPanel specialItem_panel = new JPanel();
		
		special_panel.setLayout(new GridLayout(1, 2));
		specialItem_panel.setLayout(new GridLayout(2, 1));
		specialItem_panel.setBorder(new EmptyBorder(0, 0, 10, 0));
		
		specialItem_panel.add(specialName_lbl);
		specialItem_panel.add(specialDesc_lbl);
		
		special_panel.add(specialItem_panel);
		special_panel.add(new JPanel().add(specialPrice_lbl));
		
		mainContent_panel.add(special_panel);
		/* Done adding the daily special */
		
		
		for(MenuItemType type : store.getMenuItemTypeValues()){
			JLabel typeLabel = new JLabel("<HTML><FONT SIZE = \"5\">" + type + "</FONT></HTML>");
			JPanel typePanel = new JPanel();
			typePanel.add(typeLabel);
			mainContent_panel.add(typePanel);
			
			for(int itemId : store.getMenuItemsByType(type)){
				JPanel temp_panel = new JPanel();
				temp_panel.setLayout(new GridLayout(1, 2));
				JPanel item_panel = new JPanel();
				item_panel.setLayout(new GridLayout(2, 1));
				item_panel.setBorder(new EmptyBorder(0, 0, 10, 0));
				
				JLabel name_lbl = new JLabel(store.getMenuItemName(itemId));
				JLabel desc_lbl = new JLabel(store.getMenuItemDescription(itemId));
				
				item_panel.add(name_lbl);
				item_panel.add(desc_lbl);
				
				JLabel price_lbl = new JLabel(store.getMenuItemPrice(itemId));
				JPanel price_panel = new JPanel();
				price_panel.add(price_lbl);
				
				//add all components into one-line container
				temp_panel.add(item_panel);
				temp_panel.add(price_panel);
				
				mainContent_panel.add(temp_panel);
			}
		}
		
		mainContent_panel.validate();
		JScrollPane mainContent_scroll = new JScrollPane(mainContent_panel);
		frame.add(mainContent_scroll, BorderLayout.CENTER);
	}
}